package com.suncaper.han_yi_system.exception;

import com.suncaper.han_yi_system.result.Result;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

// 全局异常处理器
@ControllerAdvice
@ResponseBody
@Hidden // 忽略此接口，不显示在文档中
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(CustomerException.class)
    public Result customerException(CustomerException customerException) {
        log.error("业务异常：{}", customerException.getMessage());
        return Result.error().code(20005).message(customerException.getMessage());
    }



    @ExceptionHandler(Exception.class)
    public Result exception(Exception exception) {
        log.error("未知异常：{}", exception.getMessage());
        return Result.error().code(50000).message("未知异常");
    }
}
